﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace YAMN_Cinemas.Presentation
{
    public partial class Admin_AddMovie1 : System.Web.UI.Page
    {
        private DateTime fromDate = new DateTime();
        Service.AdminService aservice = new Service.AdminService();
        protected void Page_Load(object sender, EventArgs e)
        {
            cal_FromDate.Visible = false;
            cal_ToDate.Visible = false;


        }
        protected void btn_Submit_Click(object sender, EventArgs e)
        {
            using (TheatreEntities te = new TheatreEntities())
            {

                foreach (ListItem l in chkbx_ScreenTime.Items)
                {
                    if (l.Selected)
                    {
                        Movy addmovie = new Movy();
                        addmovie.Movie_Title = txt_MovieName.Text;
                        addmovie.Language = ddl_Language.Text;
                        addmovie.Duration = txt_Duration.Text;
                        addmovie.Summary = txt_Summary.Text;
                        addmovie.ScreenID = Convert.ToInt64(ddl_ScreenName.SelectedValue);
                        addmovie.STID = Convert.ToInt64(l.Value);
                        addmovie.FromDate = Convert.ToDateTime(txt_FromDate.Text);
                        addmovie.ToDate = Convert.ToDateTime(txt_ToDate.Text);
                        lbl_Status.Text = "Success";
                        aservice.addmovie(addmovie);


                    }
                }


                //Movy addmovie = new Movy();
                //addmovie.Movie_Title = txt_MovieName.Text;
                //addmovie.Language = ddl_Language.Text;
                //addmovie.Duration = txt_Duration.Text;
                //addmovie.Summary = txt_Summary.Text;
                //addmovie.ScreenID = Convert.ToInt64(ddl_ScreenName.SelectedValue);
                //addmovie.STID = Convert.ToInt64(chkbx_ScreenTime.SelectedValue);
                //addmovie.FromDate = Convert.ToDateTime(txt_FromDate.Text);
                //addmovie.ToDate = Convert.ToDateTime(txt_ToDate.Text);
                //lbl_Status.Text = "Success";
                //aservice.addmovie(addmovie);



            }
        }

        protected void ddl_ScreenName_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void imgbtn_FromDate_Click(object sender, ImageClickEventArgs e)
        {
            cal_FromDate.Visible = true;
        }

        protected void imgbtn_ToDate_Click(object sender, ImageClickEventArgs e)
        {
            cal_ToDate.Visible = true;
        }

        protected void cal_FromDate_SelectionChanged(object sender, EventArgs e)
        {
            fromDate = cal_FromDate.SelectedDate;
            aservice.send_Date(fromDate);
            txt_FromDate.Text = cal_FromDate.SelectedDate.ToShortDateString();
            cal_FromDate.Visible = false;


        }

        protected void cal_ToDate_SelectionChanged(object sender, EventArgs e)
        {

            txt_ToDate.Text = cal_ToDate.SelectedDate.ToShortDateString();
            cal_ToDate.Visible = false;

        }

        protected void txt_ToDate_TextChanged(object sender, EventArgs e)
        {

        }

        protected void btn_Upload_Click(object sender, EventArgs e)
        {

            if (upload_ImageControl.HasFile)
            {
                try
                {
                    string movieid = txt_MovieName.Text;
                    string imagename = movieid;
                    string extension = Path.GetExtension(upload_ImageControl.PostedFile.FileName);
                    string upload = Request.PhysicalApplicationPath + "Images\\";
                    upload_ImageControl.SaveAs(upload + imagename + extension);
                }
                catch (Exception ex)
                {

                }
            }
        }

        protected void cal_FromDate_DayRender(object sender, DayRenderEventArgs e)
        {
            if (e.Day.IsWeekend == true)
            {
                e.Cell.ForeColor = System.Drawing.Color.Red;

            }
            if (e.Day.Date < DateTime.Today)
            {
                e.Day.IsSelectable = false;

                e.Cell.ForeColor = System.Drawing.Color.Gray;





            }


        }

        protected void cal_ToDate_DayRender(object sender, DayRenderEventArgs f)
        {
            fromDate = aservice.getdate();

            if (f.Day.Date < fromDate)
            {
                f.Day.IsSelectable = false;
                f.Cell.ForeColor = System.Drawing.Color.Gray;

            }
            //if (f.Day.IsWeekend == true)
            //{
            //    f.Cell.ForeColor = System.Drawing.Color.Red;

            //}


        }

        protected void btn_Cancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("http://localhost:6500/Presentation/Admin_Home.aspx");
        }
    }
}